<?php
// +----------------------------------------------------------------------
// | title: 标题注释
// +----------------------------------------------------------------------
// | Author: TZ.Leong
// +----------------------------------------------------------------------
// | Date: 2019/11/20 15:05
// +----------------------------------------------------------------------

namespace app\single\model;


use think\Model;

class PayTotalModel extends Model
{
    public function initialize()
    {
        $this->table  = "role_pay_total";
    }

    public function setRmb($roleId, $rmb)
    {
        $res = $this->where(["role_id" => $roleId])->setInc("rmb", $rmb);
        if($res == 0){
            $res = $this->insert(["role_id" => $roleId, "rmb" => $rmb,"last_time_recharge"=>time()]);
        }else{
            $this->where(["role_id" => $roleId])->update(["last_time_recharge"=>time()]);
        }
        return $res;
    }

    public function getRmb($roleId)
    {
        $res = $this->where(["role_id" => $roleId])->find();
        if(!$res){
            return 0;
        }else {
            return $res['rmb'];
        }
    }

}